#/bin/sh
sudo apt-get update &&\
sudo apt install -y software-properties-common &&\
sudo add-apt-repository ppa:ondrej/php &&\
sudo apt update &&\
sudo apt install composer &&\
sudo apt install php8.3 &&\
sudo apt install php8.3-common php8.3-mysql php8.3-xml php8.3-xmlrpc php8.3-curl php8.3-gd php8.3-imagick php8.3-cli php8.3-fpm php8.3-dev php8.3-imap php8.3-mbstring php8.3-opcache php8.3-soap php8.3-zip php8.3-intl php-pear -y &&\
#sudo apt-get install php php-fpm mysql-server php-mysql nginx php-pear php-dev libmcrypt-dev -y &&\
sudo rm /usr/bin/php.default &&\
sudo ln -s /usr/bin/php8.3 /usr/bin/php.default &&\
sudo apt-get install mysql-server nginx libmcrypt-dev &&\
sudo pecl install mcrypt &&\
#php_v=`ls /etc/php/` &&\
php_v=8.3 &&\
sudo cp /etc/php/${php_v}/fpm/pool.d/www.conf /etc/php/${php_v}/fpm/pool.d/www.conf.back
sudo sed -i '/^;/d' /etc/php/${php_v}/fpm/pool.d/www.conf
sudo sed -i '$aextension=mcrypt.so' /etc/php/${php_v}/fpm/php.ini &&\
sudo sed -i '$aextension=mcrypt.so' /etc/php/${php_v}/cli/php.ini &&\
sudo apt-get install php${php_v}-mbstring &&\
#sudo sed -i '/extension=mbstring/cextension=mbstring' /etc/php/${php_v}/fpm/php.ini &&\
#sudo sed -i '/extension=mbstring/cextension=mbstring' /etc/php/${php_v}/cli/php.ini &&\
sudo sed -i '/listen 80 default_server;/clisten 8080 default_server;' /etc/nginx/sites-available/default &&\
sudo sed -i '/listen \[::\]:80 default_server;/clisten \[::\]:8080 default_server;' /etc/nginx/sites-available/default &&\
sudo sed -i '/Listen 80/cListen 8081' /etc/apache2/ports.conf &&\
sudo sed -i "/listen = \/run\/php\/php${php_v}-fpm.sock/clisten = 127.0.0.1:9000" /etc/php/${php_v}/fpm/pool.d/www.conf &&\
sudo sed -i '$afastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' /etc/nginx/fastcgi_params &&\
sudo sed -i '$afastcgi_param PATH_INFO                $fastcgi_script_name;' /etc/nginx/fastcgi_params &&\
sudo mkdir /etc/nginx/ssl &&\
sudo cp -rf aajdk.com_nginx /etc/nginx/ssl/ &&\
sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.confB &&\
sudo cp nginx.conf /etc/nginx/nginx.conf &&\
sudo cp aajdk.conf /etc/nginx/conf.d/ &&\
sudo cp nginx_vhost_example.conf /etc/nginx/conf.d/phpmyadmin.conf &&\
psd_temp=`sudo sed -n '/password/p' /etc/mysql/debian.cnf | awk '{print $3}'` &&\
psd_temp1=`echo $psd_temp | awk '{print $1}'` &&\
mysql -udebian-sys-maint -p${psd_temp1} mysql -e"ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';create database ac;" &&\
sudo systemctl restart mysql.service &&\
sudo mkdir /var/www/phpmyadmin.com &&\
sudo apt install unzip &&\
sudo unzip phpMyAdmin-5.2.0-all-languages.zip &&\
sudo cp -rf phpMyAdmin-5.2.0-all-languages/* /var/www/phpmyadmin.com/ &&\
sudo cp /var/www/phpmyadmin.com/config.sample.inc.php /var/www/phpmyadmin.com/config.inc.php &&\
sudo sed -i 's/localhost/127.0.0.1/g' /var/www/phpmyadmin.com/config.inc.php &&\
sudo sed -i "s/AllowNoPassword'] = false;/AllowNoPassword'] = true;/g" /var/www/phpmyadmin.com/config.inc.php &&\
sudo sed -i '/blowfish_secret/c$cfg["blowfish_secret"] = "aca8b7c6daccb999cbcbaccbaccbaccb";' /var/www/phpmyadmin.com/config.inc.php &&\
git clone git@gitee.com:dRuin/aajdk.git &&\
sudo cp -rf aajdk /var/www/aajdk &&\
sudo php /var/www/aajdk/start.php start -d
sudo systemctl stop nginx.service
sudo systemctl stop php${php_v}-fpm.service
sudo systemctl start nginx.service
sudo systemctl start php${php_v}-fpm.service